﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Classes;

namespace OfficeManager_v0._1
{
    public partial class ProjectReportForm : Form
    {
        Project mProject;
        Organization mOrganization;

        public ProjectReportForm(Organization aOrganization, Project aProject)
        {
            InitializeComponent();
            mOrganization = aOrganization;
            mProject = aProject;


            gridViewProjectReport.Columns.Add("", "");
            gridViewProjectReport.Columns.Add("", "");

            gridViewProjectReport.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;


            try
            {
                this.Text = "Report for \"" + mProject.Subject + "\"";
            }
            catch { }

            ViewReport();
        }
        
        private void ViewReport()
        {
            try
            {
                if (mProject.Note != null)
                {
                    gridViewProjectReport.Rows.Add("Note:", mProject.Note);
                }
                if (mProject.Department != null)
                {
                    if (mProject.Department.Name != null)
                    {
                        gridViewProjectReport.Rows.Add("Department:", mProject.Department.Name);
                    }
                }

                gridViewProjectReport.Rows.Add("", "");
                gridViewProjectReport.Rows.Add("Programmers working on this project: ", "");

                if (mOrganization.Workers.Count > 0)
                {
                    try
                    {
                        foreach (var worker in mOrganization.Workers)
                        {
                            if (worker.CurrentProject.ID == mProject.ID)
                            {
                                try
                                {
                                    if (worker.Name != null)
                                    {
                                        if (worker.TelephonePost != null)
                                        {
                                            gridViewProjectReport.Rows.Add(worker.Name, "Telephone: " + worker.TelephonePost.TelephoneNumber.Number);
                                        }
                                        else
                                        {
                                            gridViewProjectReport.Rows.Add(worker.Name, "Telephone: not assigned");
                                        }

                                        if (worker.Office != null)
                                        {
                                            gridViewProjectReport.Rows.Add("Office", worker.Office.Name);
                                        }

                                        gridViewProjectReport.Rows.Add("Current position", worker.CurrentJob.Position +
                                            ", hire date: " + worker.CurrentJob.HireDate +
                                            ", payment: " + worker.CurrentJob.Payment);

                                        foreach (var job in worker.JobHistory)
                                        {
                                            gridViewProjectReport.Rows.Add("Previous position", "Hire date:" + job.HireDate +
                                                ", position: " + job.Position +
                                                ", payment" + job.Payment);
                                        }

                                    }
                                }
                                catch { }
                            }
                            gridViewProjectReport.Rows.Add("", "");
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    gridViewProjectReport.Rows.Add("No one works on this project!", "");
                }
            }
            catch { }
        }

        private void gridViewProjectReport_Resize(object sender, EventArgs e)
        {
            gridViewProjectReport.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
         
    }
}
